#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
vector<pair<int,int>> v;
set<int> st;
const int N=3e3+5;
int n,m,q;
int fa[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x,int y){fa[find(x)]=find(y);}
int cnt(){int cc=0;for(int i=1;i<=n;i++) cc+=(fa[i]==i);return cc;}
int main(){
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	int i,x,y;
	cin>>n>>m;
	v.resize(1);
	for(i=1;i<=m;i++){
		cin>>x>>y;v.pb(x,y);
	}
	cin>>q;while(q--){
		st.clear();
		int _;cin>>_;while(_--) cin>>x,st.insert(x);
		for(i=1;i<=n;i++) fa[i]=i;
		for(i=1;i<=m;i++) if(!st.count(i)) merge(v[i].first,v[i].second);
		cout<<(cnt()==1?"YES\n":"NO\n");
	}
	return 0;
}